pacman::p_load(maptools, sf, sp, rgdal, raster, spatstat, tmap, tidyverse, plotly, devtools)Spatial Point Pattern Analysis
Import packages
Data
Aspatial
before <- read_csv("data/aspatial/listings.csv")after <- read_csv("data/aspatial/listings_after.csv")colnames(before) [1] "id"
[2] "listing_url"
[3] "scrape_id"
[4] "last_scraped"
[5] "name"
[6] "summary"
[7] "space"
[8] "description"
[9] "experiences_offered"
[10] "neighborhood_overview"
[11] "notes"
[12] "transit"
[13] "access"
[14] "interaction"
[15] "house_rules"
[16] "thumbnail_url"
[17] "medium_url"
[18] "picture_url"
[19] "xl_picture_url"
[20] "host_id"
[21] "host_url"
[22] "host_name"
[23] "host_since"
[24] "host_location"
[25] "host_about"
[26] "host_response_time"
[27] "host_response_rate"
[28] "host_acceptance_rate"
[29] "host_is_superhost"
[30] "host_thumbnail_url"
[31] "host_picture_url"
[32] "host_neighbourhood"
[33] "host_listings_count"
[34] "host_total_listings_count"
[35] "host_verifications"
[36] "host_has_profile_pic"
[37] "host_identity_verified"
[38] "street"
[39] "neighbourhood"
[40] "neighbourhood_cleansed"
[41] "neighbourhood_group_cleansed"
[42] "city"
[43] "state"
[44] "zipcode"
[45] "market"
[46] "smart_location"
[47] "country_code"
[48] "country"
[49] "latitude"
[50] "longitude"
[51] "is_location_exact"
[52] "property_type"
[53] "room_type"
[54] "accommodates"
[55] "bathrooms"
[56] "bedrooms"
[57] "beds"
[58] "bed_type"
[59] "amenities"
[60] "square_feet"
[61] "price"
[62] "weekly_price"
[63] "monthly_price"
[64] "security_deposit"
[65] "cleaning_fee"
[66] "guests_included"
[67] "extra_people"
[68] "minimum_nights"
[69] "maximum_nights"
[70] "minimum_minimum_nights"
[71] "maximum_minimum_nights"
[72] "minimum_maximum_nights"
[73] "maximum_maximum_nights"
[74] "minimum_nights_avg_ntm"
[75] "maximum_nights_avg_ntm"
[76] "calendar_updated"
[77] "has_availability"
[78] "availability_30"
[79] "availability_60"
[80] "availability_90"
[81] "availability_365"
[82] "calendar_last_scraped"
[83] "number_of_reviews"
[84] "number_of_reviews_ltm"
[85] "first_review"
[86] "last_review"
[87] "review_scores_rating"
[88] "review_scores_accuracy"
[89] "review_scores_cleanliness"
[90] "review_scores_checkin"
[91] "review_scores_communication"
[92] "review_scores_location"
[93] "review_scores_value"
[94] "requires_license"
[95] "license"
[96] "jurisdiction_names"
[97] "instant_bookable"
[98] "is_business_travel_ready"
[99] "cancellation_policy"
[100] "require_guest_profile_picture"
[101] "require_guest_phone_verification"
[102] "calculated_host_listings_count"
[103] "calculated_host_listings_count_entire_homes"
[104] "calculated_host_listings_count_private_rooms"
[105] "calculated_host_listings_count_shared_rooms"
[106] "reviews_per_month"
colnames(after) [1] "id" "name"
[3] "host_id" "host_name"
[5] "neighbourhood_group" "neighbourhood"
[7] "latitude" "longitude"
[9] "room_type" "price"
[11] "minimum_nights" "number_of_reviews"
[13] "last_review" "reviews_per_month"
[15] "calculated_host_listings_count" "availability_365"
[17] "number_of_reviews_ltm" "license"
before <- subset(before, select=c(id, street, neighbourhood_cleansed, latitude, longitude))after <- subset(after, select= c(id, neighbourhood, latitude, longitude))sum(is.na(before$latitude))[1] 0
sum(is.na(before$longitude))[1] 0
sum(is.na(after$latitude))[1] 0
sum(is.na(after$longitude))[1] 0
before_sf <- st_as_sf(before, coords=c("longitude", "latitude"), crs=4326) %>% st_transform(crs=4555)after_sf <- st_as_sf(after, coords=c("longitude", "latitude"), crs=4326) %>% st_transform(crs=4555)Geospatial
nbh_sf <- st_read("data/geospatial/neighbourhoods.geojson") %>%
st_transform(crs=4555)Reading layer `neighbourhoods' from data source
`C:\annatrw\is415-gaa-grp12\analysis\SPPA\data\geospatial\neighbourhoods.geojson'
using driver `GeoJSON'
Simple feature collection with 16 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 115.4172 ymin: 39.44247 xmax: 117.5071 ymax: 41.05861
Geodetic CRS: WGS 84
st_crs(nbh_sf)Coordinate Reference System:
User input: EPSG:4555
wkt:
GEOGCRS["New Beijing",
DATUM["New Beijing",
ELLIPSOID["Krassowsky 1940",6378245,298.3,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["Topographic mapping."],
AREA["China - onshore."],
BBOX[18.11,73.62,53.56,134.77]],
ID["EPSG",4555]]
length(which(st_is_valid(nbh_sf) == FALSE))[1] 0
nbh_sf[rowSums(is.na(nbh_sf))!=0,]Simple feature collection with 16 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 115.4172 ymin: 39.44247 xmax: 117.5071 ymax: 41.05861
Geodetic CRS: New Beijing
First 10 features:
neighbourhood neighbourhood_group geometry
1 东城区 <NA> MULTIPOLYGON (((116.4423 39...
2 西城区 <NA> MULTIPOLYGON (((116.3916 39...
3 昌平区 <NA> MULTIPOLYGON (((116.0427 40...
4 大兴区 / Daxing <NA> MULTIPOLYGON (((116.7347 39...
5 房山区 <NA> MULTIPOLYGON (((116.2466 39...
6 怀柔区 / Huairou <NA> MULTIPOLYGON (((116.279 40....
7 门头沟区 / Mentougou <NA> MULTIPOLYGON (((115.563 39....
8 密云县 / Miyun <NA> MULTIPOLYGON (((116.8826 40...
9 平谷区 / Pinggu <NA> MULTIPOLYGON (((117.3813 40...
10 延庆县 / Yanqing <NA> MULTIPOLYGON (((116.279 40....
nbh_sf <- subset(nbh_sf, select=-c(neighbourhood_group))plot(st_geometry(nbh_sf))
tmap_mode("view")
tm_shape(before_sf) +
tm_dots(col="blue", size=0.05)